package com.sojson.project.sys.role.service.impl;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sojson.project.sys.role.dao.UserDeptDao;
import com.sojson.project.sys.role.entity.dto.UserDeptDto;
import com.sojson.project.sys.role.entity.dto.UserDeptPageDto;
import com.sojson.project.sys.role.entity.po.UserDept;
import com.sojson.project.sys.role.entity.vo.UserDeptVo;
import com.sojson.project.sys.role.service.UserDeptService;

/**
 * 用户和部门关联表Service实现类
 * 
 * @author liu
 * @date 2022-11-25
 */
@Service
public class UserDeptServiceImpl extends ServiceImpl<UserDeptDao, UserDept> implements UserDeptService {

    @Resource
    private UserDeptDao userDeptDao;

    /**
     * 通过对象查找
     * 
     * @param dto
     * @return
     */
    @Override
    public List<UserDeptVo> list(UserDeptDto dto) {
        List<UserDeptVo> list = userDeptDao.list(dto);
        return list;
    }

    /**
     * 通过对象分页查找
     * 
     * @param dto
     * @return
     */
    @Override
    public List<UserDeptVo> page(UserDeptPageDto dto) {
        List<UserDeptVo> page = userDeptDao.page(dto);
        return page;
    }

    /**
     * 通过对象删除
     * 
     * @param dto
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByDto(UserDeptDto dto) {
        userDeptDao.removeByDto(dto);
        return true;
    }

    /**
     * 清空数据
     * 
     * @return
     */
    @Override
    public boolean clear() {
        userDeptDao.clear();
        return true;
    }

    /**
     * 通过userId查找
     * 
     * @param id
     * @return
     */
    @Override
    public UserDeptVo findById(String id) {
        UserDeptVo findById = userDeptDao.findById(id);
        return findById;
    }

    /**
     * 通过用户ID数组删除
     * 
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteByUserIds(Set<String> ids) {
        return userDeptDao.deleteByUserIds(ids);
    }

}